package com.w3c.pragmatic.controller;

import com.w3c.pragmatic.domain.Response;
import com.w3c.pragmatic.utils.SnowflakeUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 雪花算法 前端控制器
 *
 * @author wangdong
 * @since 2025-02-20
 */
@RestController
@RequestMapping("/snowflake")
@Api(tags = "雪花算法控制层SnowflakeController")
public class SnowflakeController {

  @Resource private SnowflakeUtil snowflakeUtil;
  /**
   * 雪花算法生成随机id
   *
   * @return List<ProductInfo>
   */
  @ApiOperation(value = "雪花算法生成随机id", httpMethod = "GET")
  @RequestMapping(
      value = "/id",
      method = RequestMethod.GET,
      produces = MediaType.APPLICATION_JSON_VALUE)
  public Response<Long> getSnowflakeId() {
    return Response.ok(snowflakeUtil.nextId());
  }
}
